<template>
    <div>
        <div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<span :class="['mui-control-item',item.id===0?'mui-active':'']" v-for="item in category" :key="item.id" @click="getPhotoByCategory(item.id)">
						{{item.title}}
					</span>
				</div>
			</div>
		</div>

		<!-- 图片展示区 -->
		<ul class="lazyui">
			<router-link v-for="item in photolist" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h3 class="info-title">{{item.title}}</h3>
					<div class="info-zhaiyao">{{item.zhaiyao}}</div>
				</div>
			</router-link>
		</ul>
    </div>
</template>

<script>
//导入mui.js，使用mui初始化滑动控件
import mui from '../../../lib/mui/js/mui.js'

export default {
    data() {
        return {
			category:[],
			photolist:[]
        }
    },
    methods:{
		//获取文字对应的图片id
        async getPhotoCategory(){
			const {data}=await this.$http.get("/api/getimgcategory")
			if(data.status===0){
				data.message.unshift({title:"全部",id:0})
				this.category=data.message
			}
		},
		//加载图片
		async getPhotoByCategory(id){
			const {data}=await this.$http.get("/api/getimages/"+id)
			if(data.status===0) this.photolist=data.message
		}
    },
	mounted(){//mounted钩子函数执行的时候，踩可以进行控件或插件的初始化工作
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
	},
	created(){
		this.getPhotoCategory(),
		this.getPhotoByCategory(0)
	}

}
</script>

<style lang="scss" scoped>
    .mui-slider{
		touch-action: pan-x;
	}
	.lazyui{
		list-style-type: none;
		margin: 10px;
		padding: 0;
		li{
			position: relative;
			//排除第一个
			&+li{
				margin-top: 10px;
			}
			text-align: center;
			background-color: #ccc;
			box-shadow: 0 0 7px gray;
			img{
				display: block;
				width: 100%;
			}
			//懒加载时样式
			img[lazy=loading]{
				width: 40px;
				height: 300px;
				margin: auto;
			}
		}
	}
	.info{
		color: #fff;
		background-color: rgba(0,0,0,0.5);
		position: absolute;
		bottom: 0;
		max-height: 86px;//设置最大高度
		overflow: hidden;//超出部分隐藏
		.info-title{
			font-size: 14px;
		}
		.info-zhaiyao{
			font-size: 13px;
			text-align: left;
			text-indent: 2em;
		}
	}
</style>